<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>学生管理系统</title>
  </head>
  <body>
    <h2>学生管理系统</h2>
    <table border="1" width="100%">
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>操作</th>
        </tr>
        <% for(let i=0;i<stus.length;i++){ %>
        <tr>
            <td><%=stus[i].id%></td>
            <td><%=stus[i].name%></td>
            <td><%=stus[i].age%></td>
            <td>
                <a href="/delete/<%=stus[i].id%>" class="del">删除</a> | 
                <a href="/edit/<%=stus[i].id%>">编辑</a>
            </td>
        </tr>
        <% } %>
    </table>

    
    <fieldset>
        <legend>学生</legend>
        <form method="post">
            <p>
                <label>姓名：</label>
                <input type="text" name="name" value="<%=stu.name%>" />
            </p>
            <p>
                <label>年龄：</label>
                <input type="text" name="age" value="<%=stu.age%>" />
            </p>
            <input type="hidden" name="id" id="studentId" value="<%=stu.id%>" />
            <button formaction="/add">添加</button>
            <button  formaction="/update">更新</button>
        </form>
    </fieldset>
    

    <h4>
     <%=msg%>
    </h4>
    <script>
       let dels=document.querySelectorAll(".del");
       for(let i=0;i<dels.length;i++){
            dels[i].onclick=function(){
                return confirm("您确定要删除吗？");
            }
       }
    </script>
  </body>
</html>
